class Solution {
public:
    typedef long long ll;                                    
    int numberOfArithmeticSlices(vector<int>& nums) {
        int n = nums.size();
        vector<unordered_map<ll,int>> dp(n);
        int ret = 0;
        
        for(int i = 1;i < n;i++){
            for(int j = 0;j < i;j++){
                ll d = (ll)nums[i] - nums[j];
                if(dp[j].count(d)){
                    ret += dp[j][d];
                }
                dp[i][d] += dp[j][d] + 1;
            }
        }
        return ret;
    }
};
